package com.bdqn.mybatisjpa.mapper;

import com.bdqn.mybatisjpa.entity.SysUser;
import org.apache.ibatis.annotations.*;
import org.apache.juli.logging.Log;

import java.util.List;

public interface SysUserMapper {
    @Insert(" insert sys_user(usr_name,usr_password,usr_role_id,usr_flag) values( #{usrName}, #{usrPassword}, #{usrRoleId}, #{usrFlag})")
     void insert(SysUser sysUser);
    @Delete(" delete from sys_user where usr_id = #{id} ")
    void delete(Integer id);
    @Update("<script>" +
            " update sys_user " +
            "<set>" +
            " <if test=\"usrName != null\"> usr_name = #{usrName}, </if> " +
            "  <if test=\"usrPassword != null\"> usr_password = #{usrPassword}, </if> " +
            "  <if test=\"usrRoleId != null\"> usr_role_id = #{usrRoleId}, </if>" +
            "  <if test=\"usrFlag != null\">  usr_flag = #{usrFlag}, </if>" +
            "</set>" +
            "  where usr_id = #{usrId}"+
            "</script>"
    )
    void update(SysUser sysUser);
    @Select(" select usr_id,usr_name,usr_password,usr_role_id,usr_flag from sys_user where usr_id = #{id} ")
    @Results({
            @Result(property = "usrId",column = "usr_id"),
            @Result(property = "usrName",column = "usr_name"),
            @Result(property = "usrPassword",column = "usr_password"),
            @Result(property = "usrRoleId",column = "usr_role_id"),
            @Result(property = "usrFlag",column = "usr_flag")
    })
    SysUser get(Integer id);
    @Select(" select usr_id,usr_name,usr_password,usr_role_id,usr_flag from sys_user ")
    @Results({
            @Result(property = "usrId",column = "usr_id"),
            @Result(property = "usrName",column = "usr_name"),
            @Result(property = "usrPassword",column = "usr_password"),
            @Result(property = "usrRoleId",column = "usr_role_id"),
            @Result(property = "usrFlag",column = "usr_flag")
    })
    List<SysUser> findAll();
}
